#pragma once
#include <string>
#include <fstream>
#include "JNode.h"
#include "JBaseFile.h"
#include "JInOutPut.h"

class JFile : public JBaseFile
{
public:
	JFile(std::string _fileName);
        JFile(JBaseFile& _baseFile);
        JFile(const JFile& _file);
	JFile(void);
	~JFile(void);
	static bool IsExist(std::string fullFileName);
	static void CreateFile(std::string fileName);
	static int FileSize(std::string _fullFileName);
	std::fstream& OpenStream(std::ios_base::openmode _Mode = std::ios_base::in | std::ios_base::out,std::string _fileName="");
	void CloseStream();
	//return its' self size.
	int Serialize(JInOutPut& strea,int& allSize);
	int ReSerialize(JInOutPut& _strea);
        
        static void SaveToFileName(JInOutPut& _strea,std::string _fullFileName);
        void SaveToFileName(std::string _fullFileName);
        int  ServerSerialize(JInOutPut& _strea,int& allSize);
        void ServerReSerialize(JInOutPut& _strea);
        //在把文件存到repository的时候，会需要把tempFile拷贝到真实地址，这就是临时地址
        std::string tempFileName;
        
        //Serialize begin.
	std::fstream fs;
	//Serialize end.
        /*到远程服务器，建包*/
        int PackStubMessage(JInOutPut& _strea,int& _allSize);
        /*服务器解包*/
        int UnPackStubMessage(JInOutPut& _strea);
        //向fs中写入c
        void WriteToFile(char* c,int size);
        //void operator << (char* c,int size);
private:

};
